import { createApp } from 'vue'
import './style.css'
import App from './App.vue'
import ElementPlus from 'element-plus'
import 'element-plus/dist/index.css'
import 'virtual:windi.css'
import 'vant/lib/index.css'
import 'virtual:windi.css'
import router from './router'
import { createPinia } from 'pinia'
import Cookies from 'js-cookie';
import axios from "axios";
import Vant from 'vant';
import 'vant/lib/index.css'; // 引入 Vant CSS



// 定义一个常量来保存验证令牌的API端点
const TOKEN_CHECK_ENDPOINT = '/checktoken';

axios.interceptors.request.use(
  config => {
    // 检查是否是验证令牌的请求或高德地图API请求
    if (config.url !== TOKEN_CHECK_ENDPOINT && !config.url.includes('https://restapi.amap.com/v3/geocode/regeo')) {
      const token = Cookies.get('usertoken');
      if (token) {
        // 在请求头中添加 Bearer token
        config.headers.Authorization = `Bearer ${token}`;
      }
    } else {
      console.log("跳过为验证令牌的请求或高德地图API请求添加Authorization头");
    }

    return config;
  },
  error => {
    return Promise.reject(error);
  }
);

const app = createApp(App)

const pinia = createPinia()

app.use(ElementPlus)
app.use(Vant);
app.use(router)

app.use(pinia)

app.mount('#app')
